package com.iterator.controller.wechat.lyh;

import com.iterator.bean.web.lyh.utils.BaseRespVO;
import com.iterator.bean.wechat.lyh.WxUserIndexVO;
import com.iterator.service.wechat.lyh.WxUserService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/user")
public class WxUserController {

    @Autowired
    WxUserService wxUserService;

    /**
     * select o.order_status as `status`,count(o.order_status) as orders
     * from cskaoyanmall_order o,cskaoyanmall_user u
     * where o.user_id = (select id from cskaoyanmall_user u where u.username = 'test1') and o.user_id = u.id
     * group by o.order_status
     *
     * 本质上这个查询语句的基础是这个,因为我不知道怎么列转行,所以用了笨办法,非常难看懂
     * 101未付款 201已付款(待发货) 301已发货(待收货) 401用户收货/402系统收货(待评价)
     * 显示当前登录用户的订单状态对应的数量
     */
    //显示当前登录用户的订单状态对应的数量
    //101未付款 201已付款(待发货) 301已发货(待收货) 401用户收货/402系统收货(待评价)
    //这里401和402状态还要额外cskaoyanmall_order表中对应订单的comments不为0
    @RequestMapping("index")
    public BaseRespVO getOrderStatus(){
        //获得用户名
        String username = (String)SecurityUtils.getSubject().getPrincipal();
        WxUserIndexVO userIndexVO = wxUserService.getOrderStatus(username);
        return BaseRespVO.ok(userIndexVO);
    }
}
